package com.imooc.framework.thread;

import java.util.concurrent.*;

public class ThreadPoolDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
       //创建固定任务的线程池
//        ExecutorService executorService = Executors.newCachedThreadPool();
//        for (int i = 0; i < 10; i++) {
//            executorService.submit(new MyCallable("task" + i));
//        }
//        executorService.shutdown();






        // 创建一个线程池对象
        ThreadPoolExecutor newCachedThreadPool = new ThreadPoolExecutor(
                2, 3, 5, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());




//        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();

//        FutureTask<String> task = new FutureTask<>();
        for (int i = 0; i < 100; i++) {
            newCachedThreadPool.submit(new MyThread("CachedThreadPool"));

        }

        newCachedThreadPool.shutdown();
    }
}
